package com.content.scaffold.common.aspect;

import com.content.scaffold.common.exception.DataModifyException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author louwenliang
 */
@Aspect
@Slf4j
@Component
public class DataAspect {


    @Pointcut("execution(boolean com.baomidou.mybatisplus.extension.service.IService.*(..))")
    public void dataAspectCut() {
    }


    @AfterReturning(value = "dataAspectCut()", returning = "result")
    public void after(JoinPoint joinPoint, Object result) {
        if (result instanceof Boolean) {
            boolean flg = (boolean) result;
            if (!flg) {
                throw new DataModifyException();
            }

        } else {
            log.info("切面错误，切到除boolean外方法");
        }
    }


}
